<!--
PAGE DOCUMENTATION:
==================
This page is operated by FB in a transparent way (user doesn't see this).
All the actions that are needed when the user removes the application are done here.
-->
<?php

require_once 'facebook-platform/client/facebook.php';
require_once 'sqlLib.php';
require_once 'logsLib.php';
require_once 'server.php';

$currentPage = "remove";
$facebook = new Facebook($appapikey, $appsecret);
$user = $facebook->get_loggedin_user();
if ($user != NULL && $facebook->fb_params['uninstall'] == 1) {
	$sqlDb = new mysqli("localhost", "root", "", "messages");
		/* check connection */
		if (mysqli_connect_errno()) {
			documentError("Connect failed: ".mysqli_connect_error());
		} else {
  			if (!($sessionRemove = removeSessionKey($sqlDb,$user))) {
  				logFunctionCall($user,"removeSessionKey","sqlDb, ".$user,$sessionRemove,$currentPage);
				documentError($user,$current_page,"removeSessionKey failed");
  			}
		}
}
logAction($user,$currentPage,"removed the application");
$sqlDb = new mysqli("localhost", "root", "", "messages");
	/* check connection */
	if (mysqli_connect_errno()) {
		documentError("Connect failed: ".mysqli_connect_error());
		printErrorMsg("connecting to the database");
	} else {
		$deleteRes = deleteAllUserMessages($sqlDb,$user);
		logFunctionCall($user,"deleteAllUserMessages","sqlDb, ".$user,$deleteRes,$currentPage);
	}
//remove all user's recieved messages:


?>